<template>
	<view class="container">
		<text>房间管理页面</text>
		<text>按房间查看工程款统计</text>
	</view>
</template>

<script>
import { calculateUnpaidAmount } from '../../utils/calculations.js'

export default {
	data() {
		return {
			rooms: []
		}
	},
	onLoad() {
		this.loadRooms()
	},
	methods: {
		loadRooms() {
			const projects = uni.getStorageSync('engineering_projects') || []
			// 按房间分组统计
			const roomMap = {}
			
			projects.forEach(project => {
				const roomKey = `${project.community}-${project.room}`
				if (!roomMap[roomKey]) {
					roomMap[roomKey] = {
						community: project.community,
						room: project.room,
						projects: [],
						totalAmount: 0,
						unpaidAmount: 0
					}
				}
				
				roomMap[roomKey].projects.push(project)
				roomMap[roomKey].totalAmount += project.totalAmount
				
				// 使用统一的计算逻辑
				roomMap[roomKey].unpaidAmount += calculateUnpaidAmount(project)
			})
			
			this.rooms = Object.values(roomMap)
		}
	}
}
</script>

<style scoped>
.container {
	padding: 40rpx;
	text-align: center;
}
</style>
